package com.jinsi.controller.ylt;

import com.jinsi.constant.YltConstant;
import com.jinsi.pojo.SyUserAudit;
import com.jinsi.pojo.SyUserAuditTurn;
import com.jinsi.service.ylt.AuditListService;
import com.jinsi.util.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @ClassName AuditListController
 * @Content 申请职位审核列表Controller
 * @Author 姚龙腾
 * @Date 2022-08-06 10:40
 */
@RestController
@RequestMapping("/YltUser")
@Slf4j
public class AuditListController {

    @Autowired
    private AuditListService auditListService;


    /**
     * 获取用户封号列表信息
     * @param page
     * @param limit
     * @param auditStats
     * @return R
     */
    @RequestMapping("/AuditManage/getAuditList")
    public R getAuditList(Integer page, Integer limit,Integer auditStats){
        PageHelper.startPage(page,limit);
        List<SyUserAudit> list = auditListService.getAll(auditStats);
        PageInfo<SyUserAudit> pageInfo = new PageInfo<>(list);
        return R.custom(YltConstant.LAYUI_CODE,
                YltConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());
    }


    /**
     * 根据输入信息进行模糊查询
     * @param page
     * @param limit
     * @param auditStats
     * @param userName
     * @param auditTime
     * @return R
     */
    @RequestMapping("/AuditManage/getAuditListByLike")
    public R getAuditListByLike(Integer page, Integer limit, Integer auditStats, String userName, String auditTime){
        PageHelper.startPage(page,limit);
        List<SyUserAudit> list = auditListService.getAllByLike(auditStats, userName, auditTime);
        PageInfo<SyUserAudit> pageInfo = new PageInfo<>(list);
        return R.custom(YltConstant.LAYUI_CODE,
                YltConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());
    }


    /**
     * 修改申请审核状态
     * @param auditId
     * @param auditStats
     * @return R
     */
    @RequestMapping("/AuditManage/upAudit")
    public R upAudit(Integer auditId,Integer auditStats){
        try {
            auditListService.upAudit(auditId,auditStats);
            log.info("修改用户申请职位审核状态 upAudit方法已执行成功 修改的审核id为 ${}" ,auditId);
            return R.ok();
        } catch (Exception e) {
            log.error("修改用户申请职位审核状态 upAudit方法执行失败 报错原因 ${}" ,e);
            return R.error();
        }
    }


    /**
     * 修改申请审核状态,添加审核驳回记录
     * @param auditId
     * @param auditStats
     * @param turn
     * @return R
     */
    @RequestMapping("/AuditManage/addAuditTurn")
    public R addAuditTurn(Integer auditId, Integer auditStats, SyUserAuditTurn turn){
        try {
            auditListService.upAudit(auditId,auditStats,turn);
            log.info("修改申请审核状态,添加审核驳回记录 addAuditTurn方法已执行成功 修改的审核id为 ${}" ,auditId);
            return R.ok();
        }catch (Exception e){
            log.error("修改申请审核状态,添加审核驳回记录 addAuditTurn方法执行失败 报错原因 ${}" ,e);
            return R.error();
        }

    }
}
